<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="shortcut icon" href="favicon.ico">
    <link href="/css/bootstrap.min.css?v=3.3.5" rel="stylesheet">
    <link href="/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="/css/animate.min.css" rel="stylesheet">
    <meta http-equiv="Cache-control" content="no-cache">
    <meta http-equiv="Cache" content="no-cache">
    <link href="/css/style.min.css?v=4.0.0" rel="stylesheet">
    <base target="_blank">
    <link rel="stylesheet" href="/css/plugins/jquery-treegrid/css/jquery.treegrid.css">
</head>
<body class="gray-bg">
<!-- Panel Other -->
<div class="ibox float-e-margins">
    <table id="configRoleTable" class="table tree table-bordered table-striped table-condensed">
    </table>
    <div class="form-group">
        <div class="col-sm-8 col-sm-offset-8">
            <form class="form-horizontal m-t" id="signupForm">
                <input type="hidden" name="roleid" id="roleid" value=""/>
                <input type="hidden" name="funid" id="funid" value=""/>
            </form>
            <div class="form-group">
                <div class="col-sm-8 col-sm-offset-8">
                    <button class="btn btn-primary" id="setConfigBtn" type="button">提交</button>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="/js/jquery.min.js?v=2.1.4"></script>
<script src="/js/bootstrap.min.js?v=3.3.5"></script>
<script src="/js/content.min.js?v=1.0.0"></script>
<script src="/common/hmtool.js"></script>
<script src="/common/bootstrap-table.js"></script>
<script type="text/javascript" src="/js/plugins/jquery-treegrid/jquery.treegrid.min.js"></script>
<script type="text/javascript" src="/js/plugins/jquery-treegrid/jquery.treegrid.bootstrap3.js"></script>
<script src="/js/plugins/validate/jquery.validate.min.js"></script>
<script src="/js/plugins/validate/messages_zh.min.js"></script>
<script src="/common/form-validator.js"></script>
<script src="/common/form.js"></script>
<script src="/js/plugins/layer-pc/layer.js"></script>
<script src="/js/jquery.cookie.js"></script>
<script src="/js/jquery.serialize-object.min.js"></script>
<script type="text/javascript">
    checkPowerAndJump("CONFIGSYSROLE");
    $(function () {
        $("#roleid").val(GetQueryString("roleid"));
        var config = {
            url: SSO_URL + "sy/sysrolefun/queryRoleFunTree?roleid=" + GetQueryString("roleid"),
            id: 'configRoleTable',
            idField: 'funid',
            treeColumn: 1,
            onCheckCascade: true,
            onCheckParentCascade: true,
            onUnCheckCascade: true,
            onUnCheckParentCascade: true,
            onCheck: function (index, row, tr) {
                $(tr).treegrid("expand");
            },
            columns: [{
                field: 'st',
                checkbox: true
            }, {
                field: 'funid',
                title: '功能代码'
            }, {
                field: 'fundesc',
                title: '功能名称'
            }, {
                field: 'botflag',
                title: '是否菜单',
                formatter: function (value, row, index) {
                    return row.botflag == 0 ? '否' : '是';
                }
            }, {
                field: 'useflag',
                title: '是否使用',
                formatter: function (value, row, index) {
                    return row.useflag == 0 ? '否' : '是';
                }
            }, {
                field: 'displayfun',
                title: '显示菜单权限',
                formatter: function (value, row, index) {
                    return row.displayfun == 0 ? '否' : '是';
                }
            }, {
                field: 'orderval',
                title: '排序值'
            }]
        };
        initJQTreeTable(config);
        $("#setConfigBtn").click(function () {
            var rows = getJQTreeGridCheck("configRoleTable");
            var funids = [];
            $.each(rows, function (i, row) {
                funids.push(row.funid);
            })
            $("#funid").val(funids.join(','));
            var data = $("#signupForm").serializeObject();
            var formData = JSON.stringify(data);
            var req = {};
            req['reqJSON'] = {
                type: 'post',
                url: SSO_URL + 'sy/sysrolefun/setRoleFun',
                data: formData
            };
            req['useToken'] = true;
            req['successFn'] = function (respData) {
                layer.msg(respData.message, {icon: 6}, function () {
                    if (respData.code == SUCCESS_CODE) {
                        var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                        parent.layer.close(index);
                    }
                });
            };
            ajaxRequest(req);
        })

    });
</script>
</body>
</html>